package com.zmj.sy.mom.srv.aps.controller;

import com.zmj.sy.mom.srv.aps.bean.entity.order.Order;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseSelectResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.mbd.MbdBalanceRateReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.mbd.MbdBalanceRateResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.prescheduled.*;
import com.zmj.sy.mom.srv.aps.bean.vo.reverseorder.ReverseOrderLoadsResVo;
import com.zmj.sy.mom.srv.aps.mapper.OrderMapper;
import com.zmj.sy.mom.srv.aps.service.MbdService;
import com.zmj.sy.mom.srv.aps.service.PreScheduledService;
import com.zmj.sy.mom.srv.aps.service.ReverseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RequiredArgsConstructor
@Api(tags = "预排产")
@RestController
@RequestMapping("/preScheduled")
public class PreScheduledController {

    private final PreScheduledService preScheduledService;

    private final MbdService mbdService;
    private final ReverseOrderService reverseOrderService;
    private final OrderMapper orderMapper;

    @ApiOperation("预排产完成下拉框")
    @GetMapping("/finishSelect")
    public BaseSelectResVo finishSelect(PreScheduledFinishSelectReqVo reqVo) {
        return preScheduledService.finishSelect(reqVo);
    }

    @ApiOperation("分析报告")
    @GetMapping("/analysisReport")
    public PreScheduledAnalysisReportResVo analysisReport(PreScheduledAnalysisReportReqVo reqVo) {
        MbdBalanceRateReqVo rr1 = new MbdBalanceRateReqVo();
        rr1.setId(reqVo.getId());
        MbdBalanceRateResVo mbdBalanceRateResVo = mbdService.balanceRate(rr1);

        BigDecimal balanceRate = mbdBalanceRateResVo.getPro().getBalanceRate();

        Order order  = orderMapper.selectById(reqVo.getId());
        ReverseOrderLoadsResVo reverseOrderLoadsResVo = reverseOrderService.mbdLoads(order);

        PreScheduledAnalysisReportResVo resVo = preScheduledService.analysisReport(reqVo, reverseOrderLoadsResVo);


        resVo.setBalanceRate(balanceRate);

        return resVo;
    }

    @ApiOperation("分析报告-生产计划进度详情")
    @GetMapping("/analysisPhase")
    public BaseListResVo<PreScheduledAnalysisPhaseResVo> analysisPhase(PreScheduledAnalysisPhaseReqVo reqVo) {
        List<PreScheduledAnalysisPhaseResVo> preScheduledAnalysisPhaseResVos = preScheduledService.analysisPhase(reqVo);
        return new BaseListResVo<>(preScheduledAnalysisPhaseResVos);
    }

    @ApiOperation("分析报告-工作组负荷详情")
    @GetMapping("/analysisGroup")
    public BaseListResVo<PreScheduledAnalysisGroupResVo> analysisGroup(PreScheduledAnalysisGroupReqVo reqVo) {
        List<PreScheduledAnalysisGroupResVo> preScheduledAnalysisGroupResVos = preScheduledService.analysisGroup(reqVo);
        return new BaseListResVo<>(preScheduledAnalysisGroupResVos);
    }

    @ApiOperation("分析报告-外购件需求详情")
    @GetMapping("/analysisWl")
    public BaseListResVo<PreScheduledAnalysisWlResVo> analysisWl(PreScheduledAnalysisWlReqVo reqVo) {
        List<PreScheduledAnalysisWlResVo> preScheduledAnalysisWlResVos = preScheduledService.analysisWl(reqVo);
        return new BaseListResVo<>(preScheduledAnalysisWlResVos);
    }

}
